package com.doudou.collection.infrastructure.common.pojo.vo;

import com.doudou.collection.orm.entity.admin.SysMenu;
import com.doudou.collection.orm.vo.admin.SysMenuListVO;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName TreeSelect
 * @Description TreeSelect树结构实体类
 * @Author blue sky
 * @Date 2023/7/3 23:59
 * @Version 1.0
 */
@Data
public class TreeSelect implements Serializable {

    /**
     * 节点ID
     */
    private Long id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect() {

    }

    public TreeSelect(SysMenuListVO menu) {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }
}
